const express = require("express");
const route = express.Router();
const advModel = require("../db/model/advModel")
const isLoginMiddle = require("../middleware/isLoginMiddle") //引入权限校验中间件

route.get("/getUpdateData", isLoginMiddle, async (req, res) => {
  //拿到id
  const {
    _id
  } = req.query;

  //根据id去数据库查询当前id对应的数据
  try {
    const findResult = await advModel.findOne({
      _id
    });

    //把查询到的值响应给前端
    res.send({
      code: 10000,
      msg: "更新数据前查询当前数据成功",
      data: findResult
    })

  } catch (e) {
    console.log("更新数据前查询失败" + e.message);
    res.send({
      code: 10001,
      msg: "更新数据前查询失败" + e.message,
      data: null
    })
  }
})

module.exports = route;